﻿using UnityEngine;
using UnityEditor;

namespace BehaviorSystem
{
    /// <summary>
    /// 条件节点
    /// </summary>
    public class ConditionNode : BehaviourNode
    {
        public ConditionJudger ConditionJudger { get;protected set; }

        public ConditionNode(IBehaviorAgent agent, ConditionJudger conditionJudger) : base(agent)
        {
            IsNeedReDoPerTick = true;
            ConditionJudger = conditionJudger;
            ConditionJudger.node = this;
        }

        public override BTNodeState ExcuteNode()
        {
            OnExcuted();
            return HandleCondition();
        }

        public BTNodeState HandleCondition()
        {
            if (ConditionJudger != null && ConditionJudger.GetConditionResult()) 
            {
                CurState = BTNodeState.Success;
            }
            else
            {
                CurState = BTNodeState.Failure;
            }


            return CurState;
        }
    }
}